package com.leo;

import javafx.application.Application;
import javafx.event.Event;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

/**
 * @ClassName MouseDemo
 * @Description
 * @Author wangss
 * @date 2020.06.04 22:37
 * @Version 1.0
 */
public class MouseDemo4 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();
        an.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(an);

        HBox hBox = new HBox(10);
        hBox.setStyle("-fx-background-color: #b9ee53");

        Button b1 = new Button("button1");
        Button b2 = new Button("button2");

        Circle circle = new Circle(100d, Color.RED);
        // 边界范围点击是否有效，圆形其实是在一个正方形内
        circle.setPickOnBounds(true);
        // 阻止子组件得事件传递给父组件
        circle.setMouseTransparent(true);

        hBox.getChildren().addAll(b1, b2, circle);

        AnchorPane.setTopAnchor(hBox, 100d);
        AnchorPane.setLeftAnchor(hBox, 100d);
        an.getChildren().add(hBox);
        primaryStage.setScene(scene);
        primaryStage.setTitle("ImageViewDemo");
        primaryStage.setWidth(600d);
        primaryStage.setHeight(600d);
        primaryStage.setResizable(false);
        primaryStage.show();

        b1.setOnMouseClicked(event -> {
            System.out.println("b1.setOnMouseClicked");

            // 事件传递
            Event.fireEvent(b2, event);
        });

        b2.setOnMouseClicked(event -> {
            System.out.println("b2");
        });
    }
}
